﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using System.Data.SqlClient;
using DAO_ADMIN;
using System.Data;
namespace DAO
{
    public class XuatVienDAO
    {
        public XuatVienDTO LayThongTinXuatVien(int MaHoSo)
        {
            XuatVienDTO xv = new XuatVienDTO();
            xv.MAHOSO = MaHoSo;
            SqlConnection con =  DataProvider.ConnectionData();
            SqlCommand cmd = new SqlCommand("sp_ThemMoiHoaDonXuatVien", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaHS", SqlDbType.Int).Value = MaHoSo;

            cmd.Parameters.Add("@TongTienPhong", SqlDbType.Float);
            cmd.Parameters["@TongTienPhong"].Direction = ParameterDirection.Output;
            cmd.Parameters.Add("@TongTienDichVu", SqlDbType.Float);
            cmd.Parameters["@TongTienDichVu"].Direction = ParameterDirection.Output;
            cmd.Parameters.Add("@TongTienThuoc", SqlDbType.Float);
            cmd.Parameters["@TongTienThuoc"].Direction = ParameterDirection.Output;
            cmd.Parameters.Add("@TenBenhNhan", SqlDbType.NVarChar).Size = 200;
            cmd.Parameters["@TenBenhNhan"].Direction = ParameterDirection.Output;
            cmd.ExecuteNonQuery();
            xv.TENBENHNHAN = cmd.Parameters["@TenBenhNhan"].Value.ToString();
            if (cmd.Parameters["@TongTienPhong"].Value.ToString() != "")
            {
                xv.TONGTIENPHONG = float.Parse(cmd.Parameters["@TongTienPhong"].Value.ToString());
            }
            if (cmd.Parameters["@TongTienThuoc"].Value.ToString() != "")
            {
                xv.TONGTIENTHUOC = float.Parse(cmd.Parameters["@TongTienThuoc"].Value.ToString());
            }
            if (cmd.Parameters["@TongTienDichVu"].Value.ToString() != "")
            {
                xv.TONGTIENDICHVU = float.Parse(cmd.Parameters["@TongTienDichVu"].Value.ToString());
            }
            return xv;
        }


        public bool ThanhToanHoaDonXuatVien(int iMaHoSo)
        {
            SqlConnection con = DataProvider.ConnectionData();
            SqlCommand cmd = new SqlCommand("sp_ThanhToanHoaDonXuatVien", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaHS", SqlDbType.Int).Value = iMaHoSo;

            if (cmd.ExecuteNonQuery() != 0)
                return true;
            return false;

        }
    }
}
